package com.chris.homecare.screens.events
{
	import com.chris.homecare.components.renderers.EventCategoryListRenderer;
	import com.chris.homecare.components.renderers.ServicesListRenderer;
	import com.chris.homecare.data.DataUtil;
	import com.chris.homecare.utils.CommonUtils;
	
	import feathers.controls.Label;
	import feathers.controls.LayoutGroup;
	import feathers.controls.List;
	import feathers.controls.renderers.IListItemRenderer;
	import feathers.data.ListCollection;
	
	import starling.display.Quad;
	import starling.events.Event;
	
	[Event(name="cagegoryChange", type="starling.events.Event")]
	public class CategoryListScreen extends LayoutGroup
	{
		public static const CATEGORY_CHANGE:String = "cagegoryChange";
		private var eventCategoryList:List;
		private var eventCategoryListCollection:ListCollection;
		private var noEventLable:Label;
		
		public function CategoryListScreen()
		{
			super();
			eventCategoryListCollection = DataUtil.getAllEventsCategory();
		}
		
		override protected function initialize():void
		{
			eventCategoryList = new List();
			eventCategoryList.dataProvider = eventCategoryListCollection;
			eventCategoryList.addEventListener(Event.CHANGE, onCategoryListChange);
			eventCategoryList.itemRendererFactory = function ():IListItemRenderer
			{
				var renderer:EventCategoryListRenderer = new EventCategoryListRenderer();
				return renderer;
			};
			addChild(eventCategoryList);
			eventCategoryList.backgroundSkin = new Quad(10,10,0xFFFFFF);
			eventCategoryList.backgroundDisabledSkin = new Quad(10,10,0xFFFFFF);
			
			noEventLable = new Label();
			noEventLable.text = "No events for the next 10 days";
			noEventLable.x = noEventLable.y = 20*CommonUtils.scaleValue;
			noEventLable.nameList.add("no-message-lbl");
			addChild(noEventLable);
			
			super.initialize();
		}
		
		private function onCategoryListChange():void
		{
			this.dispatchEventWith(CATEGORY_CHANGE, false, eventCategoryList.selectedItem); 
		}
		
		override protected function draw():void
		{
			eventCategoryList.width = this.width;
			eventCategoryList.height = this.height;
			
			
			if(eventCategoryListCollection.data.length == 0)
			{
				noEventLable.visible = true;
				noEventLable.includeInLayout = true;
			}
				
			else
			{
				noEventLable.visible = false;
				noEventLable.includeInLayout = false;
			}
			
			super.draw();
		}
	}
}